<template>
  <div>
    <el-form
      ref="hotel"
      :model="hotel"
      label-width="80px"
      style="width: 60%; margin-top: 30px"
    >
      <el-form-item label="酒店名称">
        <el-input v-model="hotel.hotelName"></el-input>
      </el-form-item>
      <el-form-item label="所属区域">
        <el-cascader-panel
          :options="options"
          @change="handleChange"
        ></el-cascader-panel>
      </el-form-item>
      <el-form-item label="酒店星级">
        <el-select v-model="hotel.hotelLevel" placeholder="酒店星级">
          <el-option
            v-for="item in optionList"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="酒店地址">
        <el-input type="textarea" v-model="hotel.address"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即新增</el-button>
        <router-link to="/hotel/table" style="margin-left: 20px">
          <el-button>取消</el-button>
        </router-link>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      hotel: {
        hotelName: "",
        hotelLevel: "",
        countryId: "",
        provinceId: "",
        cityId: "",
        address: "",
      },
      optionList: [
        { id: 1, name: "经济型酒店" },
        { id: 2, name: "二星级酒店" },
        { id: 3, name: "三星级酒店" },
        { id: 4, name: "四星级酒店" },
        { id: 5, name: "五星级酒店" },
      ],
      options: [],
    };
  },
  methods: {
    handleChange(value) {
      this.hotel.countryId = value[0];
      this.hotel.provinceId = value[1];
      this.hotel.cityId = value[2];
    },
    onSubmit() {
      this.$axios
        .post("http://localhost:8080//bizhotel/itrip-hotel/hotels", this.hotel)
        .then((res) => {
          console.log(res);
          this.$router.push("/hotel/table");
        });
    },
  },
  created() {
    this.$axios
      .get("http://localhost:8080//bizhotel/itrip-hotel/addInfo")
      .then((res) => {
        this.options = res.data.data.optionVos;
      });
  },
  
};
</script>

<style>
.hotel-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .hotel-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .hotel-uploader .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .hotel-uploader img {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
